import { defineStore } from 'pinia';
import { ROOT_NOTE_KEY } from './node-tree-cache';

export const STORE_KEY_TOP_LEVEL_OPERATION = 'top-level-operation';

export interface TopLevelOperationState {
  // 新建飞书同步菜单弹框是否打开
  isNewLarkNoteOpen: boolean;
  newLarkNoteParentNoteId: string;
}

// 顶层操作相关状态
export const useTopLevelOperationStore = defineStore(STORE_KEY_TOP_LEVEL_OPERATION, {
  state: (): TopLevelOperationState => ({
    isNewLarkNoteOpen: false,
    newLarkNoteParentNoteId: ROOT_NOTE_KEY,
  }),
  actions: {
    openNewLarkNote(newLarkNoteParentNoteId: string) {
      this.isNewLarkNoteOpen = true;
      this.newLarkNoteParentNoteId = newLarkNoteParentNoteId;
    },
    closeNewLarkNote() {
      this.isNewLarkNoteOpen = false;
      this.newLarkNoteParentNoteId = ROOT_NOTE_KEY;
    },
  },
});
